<!--
 * @Author: xuhy
 * @Date: 2022-04-22 09:37:24
 * @LastEditTime: 2022-04-22 09:58:42
 * @LastEditors: Please set LastEditors
 * @Description: 分类参数
 * @FilePath: \vue_shop\src\components\goods\GoodsParams.vue
-->
<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">商品管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>参数列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card>
      <!-- 头部警告区域 -->
      <el-alert
        title="注意: 只允许为第三级分类设置相关参数！"
        type="warning"
        :closable="false"
        show-icon
      ></el-alert>

      <!-- 选择商品分类 -->
      <el-row class="cat_opt">
        <el-col>
          <span>选择商品分类:</span>
          <!-- 选择商品分类的级联选择器 -->
          <el-cascader
            v-model="selectedCateKeys"
            :options="cateList"
            :props="{
              expandTrigger: 'hover',
              checkStrictly: true,
              value: 'cat_id',
              label: 'cat_name',
              children: 'children'
            }"
            @change="parentCateChanged"
            clearable
          ></el-cascader>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // 商品分类列表
      cateList: [],
      // 级联选择框双向绑定到的数组
      selectedCateKeys: []
    }
  },
  created() {
    this.getCateList()
  },
  methods: {
    // 获取所有的商品分类
    async getCateList() {
      const { data: res } = await this.$http.get('categories')
      if (res.meta.status !== 200) {
        return this.$message.error('获取商品分类失败！')
      }
      this.cateList = res.data
      console.log(this.cateList)
    }
  }
}
</script>
<style lang="less" scoped>
.cat_opt {
  margin: 20px 0;
}
.el-cascader {
  margin-left: 15px;
}
</style>
